package com.yang.utils;

import com.yang.core.TestResultsSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName: Print
 * @Description: TODO
 * @Author: Administrator
 * @Date: 2022/3/14 18:51
 * @Version 1.0
 **/
public class Print {
    public static void print(TestResultsSet resultsSet) {
        Cumpute cumpute = new Cumpute();
        Map<String, List> results = cumpute.cumpute(resultsSet);
        Set<String> keys = results.keySet();

        System.out.println("+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+");
        System.out.printf("|%-30s|%10s|%10s|%10s|%10s|%10s|%10s|%10s|%10s|%10s%%|%15s|%16s|%16s|", "Label", "# Samples", "Average", "Median", "90% Line", "95% Line", "99% Line", "Min", "Max", "Error", "Throughput", "Received KB/sec", "Sent KB/sec");
        System.out.println();
        System.out.println("+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+");
        if (keys.size() < 1) {
            System.out.println("|                                                                              NO DATA                                                                                               |");
            System.out.println("+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+");
            return;
        }
        for (String key : keys) {
            if (key.equals("total")){continue;}
            List res = results.get(key);
            String label = (String) res.get(0);
            label = FormatLabel.formatLabel(label);

            System.out.printf("|%-10s|%10d|%10d|%10d|%10d|%10d|%10d|%10d|%10d|%10.2f%%|%11.2f/sec|%16.2f|%16.2f|", label, res.get(1), res.get(2), res.get(3), res.get(4), res.get(5), res.get(6), res.get(7), res.get(8), res.get(9), res.get(10), res.get(11), res.get(12));
            System.out.println();
        }
        List res = results.get("total");
        System.out.println("+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+");
        System.out.printf("|%-30s|%10d|%10d|%10d|%10d|%10d|%10d|%10d|%10d|%10.2f%%|%11.2f/sec|%16.2f|%16.2f|", "total", res.get(1), res.get(2), res.get(3), res.get(4), res.get(5), res.get(6), res.get(7), res.get(8), res.get(9), res.get(10), res.get(11), res.get(12));
        System.out.println();
        System.out.println("+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+");
    }
}